home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-ppc-src / ar / errors.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  2KB  |  93 lines

  1. /* $VER: ar errors.c V0.1 (31.01.98)
  2.  *
  3.  * This file is part of ar, a portable archive maintanance
  4.  * utility for normal and BSD-style archives.
  5.  * Copyright (c) 1999  Frank Wille
  6.  *
  7.  * ar is freeware and part of the portable and retargetable ANSI C
  8.  * compiler vbcc, copyright (c) 1995-99 by Volker Barthelmann.
  9.  * ar may be freely redistributed as long as no modifications are
  10.  * made and nothing is charged for it. Non-commercial usage is allowed
  11.  * without any restrictions.
  12.  * EVERY PRODUCT OR PROGRAM DERIVED DIRECTLY FROM MY SOURCE MAY NOT BE
  13.  * SOLD COMMERCIALLY WITHOUT PERMISSION FROM THE AUTHOR.
  14.  *
  15.  *
  16.  * v0.1  (31.01.99) phx
  17.  *       First working version, which only supports 'q' (quick append)
  18.  *       and 't' (table of contents), reads and writes normals and
  19.  *       BSD-style archives. Symbol table will not be created!
  20.  * v0.0  (30.01.99) phx
  21.  *       File created.
  22.  */
  23.  
  24. #include <stdio.h>
  25. #include <stdarg.h>
  26. #include "ar.h"
  27.  
  28.  
  29. /* error flags */
  30. #define EF_NONE 0
  31. #define EF_WARNING 1
  32. #define EF_ERROR 2
  33. #define EF_FATAL 3
  34.  
  35. static struct {
  36.   char *txt;
  37.   int flags;
  38. } errors[] = {
  39.   "",EF_NONE,
  40.   "Out of memory",EF_FATAL,                                         /* 01 */
  41.   "Missing archive name",EF_FATAL,
  42.   "Missing file name",EF_FATAL,
  43.   "Modifier '%c' not allowed for keyarg '%c'",EF_FATAL,
  44.   "Unknown keyarg '%c'",EF_FATAL,
  45.   "%s has a read error",EF_FATAL,
  46.   "%s: malformatted archive member %.15s",EF_ERROR,
  47.   "%s: read error at archive member %.15s",EF_ERROR,
  48.   "%s: file format not recognized",EF_ERROR,
  49.   "%s: not found in archive",EF_ERROR,                               /* 10 */
  50.   "%s: no such file or directory",EF_ERROR,
  51.   "creating archive %s",EF_WARNING,
  52.   "can't write archive",EF_FATAL,
  53.   "file name %s truncated to %s",EF_WARNING,
  54. };
  55.  
  56.  
  57. extern void cleanup(void);
  58.  
  59.  
  60.  
  61. void error(int errn,...)
  62. /* prints errors and warnings */
  63. {
  64.   va_list vl;
  65.   char *errtype;
  66.   int flags = errors[errn].flags;
  67.  
  68.   /* print error message */
  69.   fprintf(stderr,PNAME ": ");
  70.   va_start(vl,errn);
  71.   vfprintf(stderr,errors[errn].txt,vl);
  72.   va_end(vl);
  73.   fprintf(stderr,"\n");
  74.   if (flags == EF_FATAL) {
  75.     fprintf(stderr,"Aborting.\n");  /* fatal error aborts program */
  76.     cleanup();
  77.   }
  78. }
  79.  
  80.  
  81. void ierror(char *errtxt,...)
  82. /* display internal error and quit */
  83. {
  84.   va_list vl;
  85.  
  86.   fprintf(stderr,"\nINTERNAL ERROR: ");
  87.   va_start(vl,errtxt);
  88.   vfprintf(stderr,errtxt,vl);
  89.   va_end(vl);
  90.   fprintf(stderr,".\nAborting.\n");
  91.   cleanup();
  92. }
  93.